package com.ruoyi.bookkeeping.service.impl;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.bookkeeping.domain.BookSort;
import com.ruoyi.bookkeeping.domain.param.GetBookNewsParam;
import com.ruoyi.bookkeeping.mapper.BookSortMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bookkeeping.mapper.BookNewsMapper;
import com.ruoyi.bookkeeping.domain.BookNews;
import com.ruoyi.bookkeeping.service.IBookNewsService;

/**
 * 新闻Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@Service
public class BookNewsServiceImpl extends ServiceImpl<BookNewsMapper, BookNews> implements IBookNewsService
{
    @Autowired
    private BookNewsMapper bookNewsMapper;

    /**
     * 查询新闻
     * 
     * @param newsId 新闻主键
     * @return 新闻
     */
    @Override
    public BookNews selectBookNewsByNewsId(Long newsId)
    {
        return bookNewsMapper.selectBookNewsByNewsId(newsId);
    }

    /**
     * 查询新闻列表
     * 
     * @param bookNews 新闻
     * @return 新闻
     */
    @Override
    public List<BookNews> selectBookNewsList(GetBookNewsParam getBookNewsParam)
    {
        LambdaQueryWrapper<BookNews> bookNewsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        bookNewsLambdaQueryWrapper.like(StrUtil.isNotEmpty(getBookNewsParam.getNewsAuthor()),BookNews::getNewsAuthor,getBookNewsParam.getNewsAuthor())
                .like(StrUtil.isNotEmpty(getBookNewsParam.getNesType()),BookNews::getNesType,getBookNewsParam.getNesType())
                .like(StrUtil.isNotEmpty(getBookNewsParam.getNewsTitle()),BookNews::getNewsTitle,getBookNewsParam.getNewsTitle())
                .eq(!StrUtil.isBlankIfStr(getBookNewsParam.getNewsTime()),BookNews::getNewsTime,getBookNewsParam.getNewsTime());
        return baseMapper.selectList(bookNewsLambdaQueryWrapper);
    }

    /**
     * 新增新闻
     * 
     * @param bookNews 新闻
     * @return 结果
     */
    @Override
    public int insertBookNews(BookNews bookNews)
    {
        return bookNewsMapper.insertBookNews(bookNews);
    }

    /**
     * 修改新闻
     * 
     * @param bookNews 新闻
     * @return 结果
     */
    @Override
    public int updateBookNews(BookNews bookNews)
    {
        return bookNewsMapper.updateBookNews(bookNews);
    }

    /**
     * 批量删除新闻
     * 
     * @param newsIds 需要删除的新闻主键
     * @return 结果
     */
    @Override
    public int deleteBookNewsByNewsIds(Long[] newsIds)
    {
        return bookNewsMapper.deleteBookNewsByNewsIds(newsIds);
    }

    /**
     * 删除新闻信息
     * 
     * @param newsId 新闻主键
     * @return 结果
     */
    @Override
    public int deleteBookNewsByNewsId(Long newsId)
    {
        return bookNewsMapper.deleteBookNewsByNewsId(newsId);
    }
}
